﻿using FluentScheduler;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FluentSchedulerApp
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
            cmbJobType.SelectedIndex = 0;
            dtpJobTime.Format = DateTimePickerFormat.Custom;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            JobManager.Initialize();

            JobManager.AddJob(
                () => Console.WriteLine("5分钟过去了."),
                s => s.ToRunEvery(5).Minutes()
            );


            JobManager.AddJob(
    () => Console.WriteLine("每天 20 点 15 执行一次 "),
    s => s.ToRunEvery(1).Days().At(20, 15)
);

            JobManager.AddJob(
                () => Console.WriteLine("定时 2023年10月10日 执行"),
                s => s.ToRunOnceAt(new DateTime(2023, 10, 10))
            );

            JobManager.AddJob(
                () => Console.WriteLine("每 5s 执行一次..."),
                s => s.ToRunOnceIn(5).Seconds()
            );

            JobManager.AddJob(
    () => Console.WriteLine("001 任务"),
    s => s.WithName("001").ToRunEvery(1).Days().At(20, 15)
);

            JobManager.RemoveJob("001");


        }

        private void btBrowFile_Click(object sender, EventArgs e)
        {
            //创建对象
            OpenFileDialog ofg = new OpenFileDialog();
            //判断保存的路径是否存在
            if (!Directory.Exists(string.Concat(System.AppDomain.CurrentDomain.BaseDirectory, "Plugins")))
            {
                //创建路径
                Directory.CreateDirectory(string.Concat(System.AppDomain.CurrentDomain.BaseDirectory, "Plugins"));
            }
            //设置默认打开路径
            ofg.InitialDirectory = string.Concat(System.AppDomain.CurrentDomain.BaseDirectory, "Plugins");
            //设置打开标题、后缀
            ofg.Title = "请选择导入插件文件";
            ofg.Filter = "dll文件|*.dll";
            string path = "";
            if (ofg.ShowDialog() == DialogResult.OK)
            {
                //得到打开的文件路径（包括文件名）
                path = ofg.FileName.ToString();
                MessageBox.Show("打开文件路径是：" + path);
            }
        }
    }
}
